<!--
    Copyright 2010 Justin Lipton, Jonathan Rosenberg
    
    This file is part of MediaList.

    MediaList is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    MediaList is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with MediaList.  If not, see <http://www.gnu.org/licenses/>.
-->

<?php
$name=$_GET["name"];
$numeps = $_GET["numeps"];
$eplen = $_GET["eplen"];
$summary = $_GET["summary"];
$month = $_GET["month"];
$day = $_GET["day"];
$year = $_GET["year"];

$db = new mysqli("localhost", "root", null , "DB");

$error = "";

$stmt = $db -> prepare("SELECT count(*) FROM Shows WHERE Showname=?");
$stmt -> bind_param("s", $name);
$stmt -> execute();
$stmt -> bind_result($row["count"]);
$stmt -> fetch();
    
if($row["count"]==1)
{
    $error = $error."Show already exists<br />";
}
if($year<1700 || $year>Date('Y')) //checks current year
{
    $error = $error."Invalid year<br />";
}
$stmt -> fetch();

if($error == ""){
    $whenMade = $year."-".$month."-".$day;//create full whenMade in DATE format
    
    $stmt = $db -> prepare("INSERT INTO Shows (Showname, ForumLink, NumEpisodes, 
        EpisodeLength, Summary, WhenMade, TotalScores, TotalSeen, TotalFav) 
        VALUES (?, NULL, ?, ?, ?, ?, 0, 0, 0)");
    $stmt -> bind_param("siiss", $name, $numeps, $eplen, $summary, $whenMade);
    $stmt -> execute();
        
    //**change the redirect to the show's page
    echo "<meta http-equiv=\"REFRESH\" content=\"0;url=index.php\">";
}
else
{
    echo $error;
}
$db -> disconnect();
?>

